package com.hippo.core.controller;

import com.alibaba.fastjson.JSONObject;
import com.hippo.core.service.ProjectService;
import com.hippo.core.util.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.hippo.core.config.annotation.RequiresPermissions;

/**
 * @author: hippo
 */
@RestController
public class ProjectController {

    @Autowired
    private ProjectService projectService;

    @RequiresPermissions("project:list")
    @PostMapping("/getProjectList")
    public JSONObject getProjectList(@RequestBody JSONObject data) {
        return projectService.getProjectList(data);
    }

    @RequiresPermissions("project:add")
    @PostMapping("/addProject")
    public JSONObject addProject(@RequestBody JSONObject data) {
        CommonUtil.hasAllRequired(data, "name,description,status,createUser");
        return projectService.addProject(data);
    }

    @RequiresPermissions("project:delete")
    @DeleteMapping("/deleteProject/{id}")
    public JSONObject deleteProject(@PathVariable String id) {
        return projectService.deleteProject(id);
    }

    @RequiresPermissions("project:update")
    @PutMapping("updateProject")
    public JSONObject updateProject(@RequestBody JSONObject data) {
        return projectService.updateProject(data);
    }

    @GetMapping("getProjectDropdown")
    public JSONObject getProjectDropdown() {
        return projectService.getProjectDropdown();
    }

}
